package icu.funkye.controller;

import com.alibaba.fastjson.JSONObject;
import icu.funkye.mapper.OrdersMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import icu.funkye.entity.Orders;
import icu.funkye.service.IOrdersService;

import java.time.LocalDateTime;

/**
 * @author funkye
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    private final static Logger logger = LoggerFactory.getLogger(OrderController.class);
    @Autowired
    IOrdersService ordersService;

    @Autowired
    OrdersMapper ordersMapper;

    @RequestMapping("/save")
    public Orders save(@RequestBody Orders orders) throws Exception {
        if(orders.getSum()>1) {
            throw new Exception("参数越界");
        }
        logger.info("订单详情:{}", JSONObject.toJSON(orders));
            orders.setCreateTime(LocalDateTime.now());
            orders.setReplaceTime(LocalDateTime.now());
            ordersService.save(orders);
        return orders;
    }
}
